<?php
/**
 * Created by PhpStorm.
 * User: paperen
 * Date: 2020/6/17
 * Time: 21:09
 */

namespace App\Repositories\Task;

use App\Repositories\Repository;
use Illuminate\Support\Facades\DB;


/**
 * Class TaskSubmitRepository
 * @package App\Repositories\Task
 * @version v1.3
 */
class TaskSubmitRepository extends Repository
{
	// 多少天未审核标记为申诉失败
	protected $_diff = 1;
	// 超过多少天未通过记录不允许申诉
	protected $_unpass_reject_diff = 2;

	//
	const STATE_APPROVALING = 1;
	const STATE_REJECT = 4;
	const STATE_UNPASS = 3;

    /**
     * @return string
     */
    public function model()
    {
        return \App\Models\Task\TaskSubmitModel::class;
    }

    public function getTimeoutReject() {
    	$time = date('Y-m-d H:i:00', strtotime("-{$this->_diff} days"));
		return $this->model
			->where('rejecttime', '<=', $time)
			->where('state', self::STATE_REJECT)
			->pluck('id');
	}

	public function getUnpassTimeout() {
		$time = strtotime("-{$this->_unpass_reject_diff} days");
		$start = date('Y-m-d H:i:00', $time);
		$end = date('Y-m-d H:i:59', $time);
		return $this->model
			->where('approvaltime', '>=', $start)
			->where('approvaltime', '<=', $end)
			->where('state', self::STATE_UNPASS)
			->pluck('task_id');
	}

	public function getApprovalingRecord() {
		return $this->model
			->where('state', self::STATE_APPROVALING)
			->get();
	}

}
